//
//  RecreationPageViewController.m
//  Happy to chat
//
//  Created by lanou3g on 15/12/8.
//  Copyright © 2015年 LL. All rights reserved.
//

#import "RecreationPageViewController.h"
#import "RecreationManager.h"
#import "RecreationViewCell.h"
#import "RecreationModel.h"
#import "MJRefresh.h"
#import "UMSocial.h"
@interface RecreationPageViewController ()<RecreationViewCellDelegate>
//声明单利
@property (nonatomic, strong)RecreationManager *recreationManager;

@end

@implementation RecreationPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"RecreationViewCell" bundle:nil] forCellReuseIdentifier:@"recreationViewCell"];
    self.recreationManager = [RecreationManager defaultRecraetionManager];
    //刷新列表
    [self.recreationManager prepareMoviePageWithHandle:^{
        [self.tableView reloadData];
    }];
    [self addRefreshAndLoadMore];
    
    
}
//上啦刷新和下拉加载的方法
- (void)addRefreshAndLoadMore {
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(footerUpRefresh)];
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(handerDownRefresh)];
    
}
/**
 上拉加载
 */
- (void)footerUpRefresh {
    self.recreationManager.UPorDown = YES;
    [self.recreationManager prepareMoviePageWithHandle:^{
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
    }];
}

/**
 下拉刷新
 */
- (void)handerDownRefresh {
    self.recreationManager.UPorDown = NO;
    [self.recreationManager prepareMoviePageWithHandle:^{
        [self.tableView reloadData];
        [self.tableView.mj_footer endRefreshing];
    }];
}

-(void)share{
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"56683658e0f55a568b002dde"
                                      shareText:@"你要分享的文字"
                                     shareImage:[UIImage imageNamed:@""]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToQQ,UMShareToEmail,UMShareToQzone,nil]
                                       delegate:nil];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.recreationManager returnModelArrayCount];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 240;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RecreationViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"recreationViewCell" forIndexPath:indexPath];
    
    // Configure the cell...
    [self.recreationManager shiFang];
    [cell.button setBackgroundImage:[UIImage imageNamed:@"video_play_medium"] forState:UIControlStateNormal];
    cell.button.titleLabel.text = @"playButton";
     cell.delegate = self;
    RecreationModel *movie = [self.recreationManager returnMovieModelWithIndex:indexPath.row];
    [cell setupViewsWithModel:movie];
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
